/*
 * test.h
 *
 * Test Macros and helpers
 */

#ifndef TEST_H_
#define TEST_H_

#include <avr/pgmspace.h>

#ifdef __cplusplus
extern "C" {
#endif

// Output a message from a constant string
#define PRINT_LITERAL(literal_string) do { \
	static char var[] PROGMEM = (literal_string); \
	print_msg(var); \
    } while(0)

//
// Prints a hex number
void print_hex(uint16_t num);

//
// Output a message from a pointer to a constant string
void print_msg(PGM_P msg);

//
// Macros for building unit test cases
// DEF_TEST(blah) declares test method and begins function definition
// END_TEST ends function definition
#define DEF_TEST(name) \
	int test_ ## name (void) { \
	PRINT_LITERAL("Test " #name ": "); \
	PGM_P err = NULL;
#define END_TEST \
	if (err) { \
		print_msg(err); \
	} else { \
		PRINT_LITERAL("PASS\n"); \
	} \
	return !err; \
	}

// Calls the test method
#define CALL_TEST(name) test_ ## name ()

// Use with a DEF_TEST test case to check an assertion
#define CHECK(expr) do { \
	if (err == NULL && !(expr)) { \
		static char str[] PROGMEM = "FAILED (" #expr ")\n"; \
		err = str; \
	} \
} while (0)

// The tests to run
void run_tests(void);

#ifdef __cplusplus
}
#endif

#endif /* TEST_H_ */
